<include file="Public:header" />
<!--主体内容-->
<!--左边-->
<div class="centent_box">
    <include file="Public:left" />
    <!--右边-->
    <div class="centent_right_box">
        <div class="centent_right rightCon">
            <div class="Mtitle">
                <ul>
                    <li class="on"><span>房源管理</span></li>
                </ul>
                <div class="rightWord"><a href="{:U('used/add')}">新增房源</a> &gt;&gt; 数据录入</div>
            </div>
            <form id="info_form" action="{:U('Used/add')}" method="post" enctype="multipart/form-data">
                <div class="con_div">
                    <ul class="formList width2 list_ul list_mp">
                        <li>
                            <label>房源名称：</label>
                            <input type="text"  name="data[title]" class="inputStyle width3" value="{$title}" readonly>
                        </li>
                        <li>
                            <label>房源编码：</label>
                            <input type="text"  name="data[encoded]" id="encoded" class="inputStyle width3" >
                        </li>
                        <li>
                            <label>楼栋：</label>
                            <input type="text"  name="build[alias]"  class="inputStyle width5" value="{$build.alias}" data="{$build.alias}">
                            <input type="hidden"  name="build[bid]" value="{$build.bid}">
                            <if condition="$unit_count gt 1">
                                <label>单元：</label>
                                <input type="text"  name="unit[alias]" class="inputStyle width5" value="{$unit.alias}" data="{$unit.alias}">
                            </if>
                            <input type="hidden"  name="unit[unid]" value="{$unit.unid}">
                            <label>楼层：</label>
                            <input type="text"  name="room[f_alias]" class="inputStyle width5" value="{$room.f_alias}" data="{$room.f_alias}">
                            <label>门牌：</label>
                            <input type="text"  name="room[alias]" class="inputStyle width5" value="{$room.alias}" data="{$room.alias}">
                            <span class="tip">（房号：<em id="roomno">{$room.f_alias}{$room.alias}</em>）</span>
                            <input type="hidden"  name="room[rid]" value="{$room.rid}">
                            <input type="hidden"  name="room[floor]" value="{$room.floor}">
                        </li>
                        <li>
                            <label>选择户型：</label>
                            <input type="number"  name="chamber" value="{$room.chamber}" data="{$room.chamber}" class="inputStyle used_type" style="width: 50px" min="0" max="100" value="1">
                            <span class="tip">室</span>
                            <input type="number"  name="hall" value="{$room.hall}" data="{$room.hall}" class="inputStyle used_type" style="width: 50px" min="0" max="100" value="0">
                            <span class="tip">厅</span>
                            <input type="number"  name="toilet" value="{$room.toilet}" data="{$room.toilet}" class="inputStyle used_type" style="width: 50px" min="0" max="5" value="0">
                            <span class="tip">卫</span>
                            <input type="number"  name="kitchen" value="{$room.kitchen}" data="{$room.kitchen}" class="inputStyle used_type" style="width: 50px" min="0" max="5" value="0">
                            <span class="tip">厨</span>
                            <input type="number"  name="balcony" value="{$room.balcony}" data="{$room.balcony}" class="inputStyle used_type" style="width: 50px" min="0" max="5" value="0">
                            <span class="tip">阳台</span>
                        </li>
                        <li class="dict-info">
                            <label>面积：</label>
                            <input type="text" class="inputStyle width2 required" name="room[area]" value="{$room.area}" data="{$room.area}" id="proportion" >
                            <span class="tip">平方米</span>

                        </li>
                        <if condition="$sell_type eq 1">
                            <li id="li-total">
                                <label>售价：</label>
                                <input type="text" class="inputStyle width2 required" name="data[total_price]" id="total" placeholder="万元">
                                <span class="tip">万元</span>
                                <label class="label1">均价：</label>
                                <input type="text" class="inputStyle width2" name="data[average_price]"  placeholder="元/平方米" id="average" readonly>
                                <span class="tip">元/平方米</span>
                            </li>
                        <elseif condition="$sell_type eq 2" />
                            <li id="li-rental">
                                <label>租金：</label>
                                <input type="text" class="inputStyle width2 required" name="data[rental_price]" id="rental" placeholder="元">
                                <span class="tip">元/月</span>
                            </li>
                        <else />
                            <li id="li-total">
                                <label>售价：</label>
                                <input type="text" class="inputStyle width2 required" name="data[total_price]" id="total" placeholder="万元">
                                <span class="tip">万元</span>
                                <label class="label1">均价：</label>
                                <input type="text" class="inputStyle width2" name="data[average_price]"  placeholder="元/平方米" id="average" readonly>
                                <span class="tip">元/平方米</span>
                            </li>
                            <li id="li-rental">
                                <label>租金：</label>
                                <input type="text" class="inputStyle width2 required" name="data[rental_price]" id="rental" placeholder="元">
                                <span class="tip">元/月</span>
                            </li>
                        </if>
                        <li>
                            <label>联系人 ：</label>
                            <input type="text" class="inputStyle width1 required" name="data[contacts]">
                            <span class="tip">必填项</span>
                        </li>
                        <li>
                            <label>联系电话：</label>
                            <input type="text" class="inputStyle required ismobile" name="data[phone]" >
                            <span class="tip">必填项</span>
                            <button onclick="addPhone (this)" id="btu-phone">新增</button>
                        </li>
                        <li style="display: none;" id="phone-other">
                            <label>其它电话：</label>
                            <input type="text" class="inputStyle required ismobile" name="data[phone1]" style="width:150px;margin-right: 20px;display: none" id="phone1">
                            <input type="text" class="inputStyle required ismobile" name="data[phone2]" style="width:150px;margin-right: 20px;display: none" id="phone2">
                            <input type="text" class="inputStyle required ismobile" name="data[phone3]" style="width:150px;margin-right: 20px;display: none" id="phone3">
                        </li>
                        <li class="li_radio">
                            <label class="lw90">朝向：</label>
                            <div class="label_">
                            <input type="radio" name="room[aspect]" id="orientations109" value="10" <if condition="$room['aspect'] eq 10">checked</if> >
                            <label for="orientations109">西北</label>
                            <input type="radio" name="room[aspect]" id="orientations108" value="9" <if condition="$room['aspect'] eq 9">checked</if> >
                            <label for="orientations108">西南</label>
                            <input type="radio" name="room[aspect]" id="orientations107" value="8" <if condition="$room['aspect'] eq 8">checked</if> >
                            <label for="orientations107">东北</label>
                            <input type="radio" name="room[aspect]" id="orientations106" value="7" <if condition="$room['aspect'] eq 7">checked</if> >
                            <label for="orientations106">东南</label>
                            <input type="radio" name="room[aspect]" id="orientations105" value="6" <if condition="$room['aspect'] eq 6">checked</if> >
                            <label for="orientations105">南北</label>
                            <input type="radio" name="room[aspect]" id="orientations104" value="5" <if condition="$room['aspect'] eq 5">checked</if> >
                            <label for="orientations104">东西</label>
                            <input type="radio" name="room[aspect]" id="orientations103" value="4" <if condition="$room['aspect'] eq 4">checked</if> >
                            <label for="orientations103">北</label>
                            <input type="radio" name="room[aspect]" id="orientations102" value="3" <if condition="$room['aspect'] eq 3">checked</if> >
                            <label for="orientations102">南</label>
                            <input type="radio" name="room[aspect]" id="orientations101" value="2" <if condition="$room['aspect'] eq 2">checked</if> >
                            <label for="orientations101">西</label>
                            <input type="radio" name="room[aspect]" id="orientations100" value="1" <if condition="$room['aspect'] eq 1">checked</if> >
                            <label for="orientations100">东</label>
                            </div>
                        </li>
                        <li class="li_checkbox" id="mating">
                            <label class="lw90">房屋配套：</label>
                            <input type="checkbox" name="mating[]" id="mating1" value="1"><label for="mating1">冰箱</label>
                            <input type="checkbox" name="mating[]" id="mating2" value="2"><label for="mating2">床</label>
                            <input type="checkbox" name="mating[]" id="mating3" value="3"><label for="mating3">衣橱</label>
                            <input type="checkbox" name="mating[]" id="mating4" value="4"><label for="mating4">热水器</label>
                            <input type="checkbox" name="mating[]" id="mating5" value="5"><label for="mating5">沙发</label>
                            <input type="checkbox" name="mating[]" id="mating6" value="6"><label for="mating6">电视</label>
                            <input type="checkbox" name="mating[]" id="mating7" value="7"><label for="mating7">网络</label>
                            <input type="checkbox" name="mating[]" id="mating8" value="8"><label for="mating8">家电齐全</label>
                            <input type="checkbox" name="mating[]" id="mating9" value="9"><label for="mating9">家私齐全</label>
                        </li>
                        <if condition="$room['img'] neq null">
                            <li style="height: 220px" id="used-type">
                                <label>户型图：</label>
                                <div style="display:inline-table;width: 200px;height: 200px">
                                    <img src="{$room.img}" width="200px" height="200px"/>
                                </div>
                                <button onclick="alter (this)">修改</button>
                            </li>

                        <else />
                            <li>
                                <label>户型图：</label>
                                <input type="file" name="img" id="img">
                            </li>

                        </if>
                        <li>
                            <label>产权：</label>
                            <select name="data[property]" id="property" class="selectStyle">
                                <option value="0" selected>请选择</option>
                                <option value="15">红本五年一套</option>
                                <option value="16">红本两年多套</option>
                                <option value="17">贷款五年一套</option>
                                <option value="18">贷款两年多套</option>
                                <option value="19">贷款不满两年</option>
                                <option value="21">红本不满两年</option>
                                <option value="12">红本在手</option>
                            </select>
                            <label>用途：</label>
                            <select name="data[purpose]" id="purpose" class="selectStyle">
                                <option value="1">住宅</option>
                                <option value="2">写字楼</option>
                                <option value="3">商铺</option>
                                <option value="4">商务公寓</option>
                                <option value="5">厂房</option>
                            </select>
                        </li>
                        <li>
                            <label>钥匙人 ：</label>
                            <select name="data[keyer]" id="keyer" class="selectStyle">
                                <option value="">请选择</option>
                                <volist name="users" id="vo">
                                    <option value="{$vo.id}">{$vo.username}</option>
                                </volist>
                            </select>
                            <label>钥匙编号 ：</label>
                            <input type="text" class="inputStyle width1" name="data[keyno]">
                        </li>
                        <li>
                            <label>维护人 ：</label>
                            <select name="data[maintain]" id="maintain" class="selectStyle">
                                <option value="">请选择</option>
                                <volist name="users" id="vo">
                                    <option value="{$vo.id}" {$vo.sele}>{$vo.username}</option>
                                </volist>
                            </select>
                        </li>

                        <li id="files">
                            <label>室内图：</label>
                            <script id="uploadpic" name="uploadpic" type="text/plain"></script>
                            <input type="button" class="btn btn_submit" style="margin:0 0 10px 10px;" onclick="upImage();" value="选择图片">
                            <div id="imageList">
                                <ul class="list clearfix"></ul>
                            </div>
                            <input type="hidden" name="file" id="file" />
                        </li>
                        <li class="li_radio">
                            <label class="lw90">装修情况：</label>
                            <div class="label_">
                                <input type="radio" name="decorate" id="renovation_type70" value="4"><label for="renovation_type70">豪装</label>
                                <input type="radio" name="decorate" id="renovation_type68" value="3"><label for="renovation_type68">精装</label>
                                <input type="radio" name="decorate" id="renovation_type67" value="2"><label for="renovation_type67">简装</label>
                                <input type="radio" name="decorate" id="renovation_type69" value="1"><label for="renovation_type69">毛坯</label>
                            </div>

                        </li>

                        <li>
                            <label>建筑年代：</label>
                            <input type="text" class="inputStyle width2" name="estate[years]" value="{$estate.years}" id="years" readonly>
                            <span class="tip">年</span>
                            <input type="hidden" name="estate[id]" value="{$estate.id}">
                            <input type="hidden" name="estate[area_id]" value="{$estate.area_id}">
                        </li>
                        <li>
                            <label>所在地址：</label>
                            <input type="text" class="inputStyle width3" name="estate[address]" value="{$estate.address}" id="addr" readonly>
                            <span class="tip">中文字符</span>
                        </li>
                        <li>
                            <label>地图标注：</label>
                            <input type="text" class="inputStyle" name="estate[map]" id="map" value="{$estate.map}" readonly>
                        </li>

                        <li class="height1">
                            <label>特色标签：</label>
                            <textarea class="textarea" id="tags" name="data[tags]" placeholder="多个使用使用逗号 ，隔开"></textarea>
                        </li>
                        <li class="height2">
                            <label>详细介绍：</label>
                            <textarea name="data[info]" id="info" style="width:100%;height:300px;resize: none;float:left"></textarea>
                        </li>
                        <input type="hidden"  name="data[area_id]" value="{$estate.area_id}">
                        <input type="hidden"  name="data[img]" id="img-url">
                        <li>
                            <label></label>
                            <input type="submit" value="提 交" class="btnStyle">
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
</div>
<js file="__S__/ueditor/ueditor.config.js" charset="utf-8" />
<js file="__S__/ueditor/ueditor.all.min.js" charset="utf-8" />
<js file="__S__/ueditor/lang/zh-cn/zh-cn.js" charset="utf-8" />
<js file="__JS__/uploadImg.js" charset="utf-8" />
<script type="text/javascript">
    window.UEDITOR_HOME_URL='__STATIC__/ueditor/';
    window.onload=function(){
        window.UEDITOR_CONFIG.initialFrameWidth=880;
        window.UEDITOR_CONFIG.initialFrameHeight=500;
        upmoreimg();
    }
    var ue = UE.getEditor('info', {
        toolbars: [[
            'fullscreen', 'source', '|',
            'bold', 'italic', 'underline', '|', 'fontfamily','fontsize', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', 'simpleupload','|', 'kityformula', 'preview'
        ]]
    });
</script>
<script src="__S__/js/ajaxfileupload.js"></script>
<script src="__S__/js/jquery.validate.js"></script>
<script src="__S__/js/magess.js"></script>
<script src="__S__/js/jquery.metadata.js"></script>
<script type="text/javascript">
    $().ready(function() {
        $("#info_form").validate();
        jQuery.validator.addMethod("ismobile", function(value, element) {
            var length = value.length;
            var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
            return this.optional(element) || (length == 11 && mobile.test(value));
        }, "请正确填写您的手机号码");
    });

</script>
<script>
    $("#sell_type").change (function (){
        var id = $(this).val();
        if (id == 1){
            $('#li-rental').hide();
            $('#li-total').show();
        }
        if (id == 2){
            $('#li-rental').show();
            $('#li-total').hide();
        }
        if (id == 3){
            $('#li-rental').show();
            $('#li-total').show();
        }
    });
    $("input[name='build[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='build[bid]']").val();
            var alias = $("input[name='build[alias]']").val();
            var data = {id:id,val:alias,table:'build',type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='build[bid]']").val();
            var alias = $("input[name='build[alias]']").val();
            var data = {id:id,val:alias,table:'build',type:'alias'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='unit[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='unit[unid]']").val();
            var alias = $("input[name='unit[alias]']").val();
            var data = {id:id,val:alias,table:'unit',type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='unit[unid]']").val();
            var alias = $("input[name='unit[alias]']").val();
            var data = {id:id,val:alias,table:'unit',type:'alias'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[f_alias]']").change(function(){
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[f_alias]']").val();
            var data = {id:id,val:alias,table:'room',type:'f_alias'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        var room = $("input[name='room[alias]']").val();
                        $('#roomno').html(alias+room);
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[alias]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[alias]']").val();
            var floor = $("input[name='room[floor]']").val();
            var data = {id:id,val:alias,table:'room',floor:floor,type:'alias'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg(response.msg, {icon: 0});
                    location.reload(1);
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[alias]']").val();
            var floor = $("input[name='room[floor]']").val();
            var data = {id:id,val:alias,table:'room',floor:floor,type:'alias'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        $('#roomno').html(floor+alias);
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg(response.msg, {icon: 0});
                        location.reload(1);
                    }
                }
            });

        }, function(){
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[area]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[area]']").val();
            var data = {id:id,val:alias,table:'room',type:'area'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            $('#total').val(0.00);
            $('#average').val(0.00);
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[area]']").val();
            var data = {id:id,val:alias,table:'room',type:'area'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$room.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    $("input[name='room[aspect]']").change(function (){
        var lastVal = $(this).attr ('data');
        var tar = $(this);
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[aspect]']:checked").val();
            var data = {id:id,val:alias,table:'room',type:'aspect'}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[aspect]']:checked").val();
            var data = {id:id,val:alias,table:'room',type:'aspect'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    $('.used_type').change(function (){
        var tar = $(this);
        var lastVal = $(this).attr ('data');
        var currentVal = tar.val ();
        if (lastVal == '' || lastVal == 0){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = tar.val();
            var type = tar.prop('name');
            var data = {id:id,val:alias,table:'room',type:type}
            $.post (url, data, function (response){
                if (response.state == 'ok'){
                    tar.attr ('data', currentVal);
                    return true;
                }else{
                    layer.msg('更新失败！', {icon: 0});
                }
            },'json');
            return true;
        }
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = tar.val();
            var type = tar.prop('name');
            var data = {id:id,val:alias,table:'room',type:type}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });
    /*$("#img").change(function (){
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            $('#total').val(0.00);
            $('#average').val(0.00);
            var url = "{:U ('Ajax/setDict')}";
            var id = $("input[name='room[rid]']").val();
            var alias = $("input[name='room[aspect]']:checked").val();
            var data = {id:id,val:alias,table:'room',type:'aspect'}
            $.ajax({
                type : "post", url : url, data : data, dataType : 'json', async : false,
                success : function(response){
                    if (response.state == 'ok'){
                        layer.msg('更新成功！', {icon: 1});
                    }else{
                        layer.msg('更新失败！', {icon: 0});
                    }
                }
            });

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    });*/
    $('#total').keyup(function(){
        var total = $(this).val();console.log(total);
        var area = $('#proportion').val();console.log(area);
        var average = parseFloat(total)/parseFloat(area)*10000;
        $('#average').val(average.toFixed(2));
    })
    //新增电话号码
    function addPhone (tar){
        event.preventDefault();//阻制默认事件
        window.event.returnValue;
        layer.open({
            type: 1,
            area: ['300px', ''],
            anim: 2,
            content: '<div style="margin-top: 20px"><ul class="formList list_ul clear">' +
            '<li><label>手机号：</label><input type="number" name="phone1" class="inputStyle width2 ismobile" /></li>' +
            '</ul><div style="margin:50px 10px 10px 100px">' +
            '<button onclick="phone(this)">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
            '<button onclick="javascripy:layer.closeAll()">取消</button>' +
            '</div></div>'
        });
    }
    var phoneCount = 0;
    function phone (tar){
        var phone = $('input[name=phone1]').val();
        phoneCount += 1;
        if (phoneCount > 3){
            layer.msg('最多只能添加3个号码', {icon: 0});
            return false;
        }
        $('#phone-other').show ();
        $('#phone'+phoneCount).show ();
        $('#phone'+phoneCount).val(phone);
        layer.closeAll();
    }
    function alter (tar){
        event.preventDefault();
        window.event.returnValue;
        var prevElem = $('#used-type').prev('li');
        $('#used-type').remove();
        prevElem.after('<li><label>户型图：</label><input type="file" name="img" id="img"></li>');
        layer.closeAll();

    }
    //户型图
    $('#info_form').on("change","#img",function(e){
        layer.confirm('值已改变，是否更新到数据字典！', {
            btn: ['是','否']
        }, function(){
            var url = "{:U ('Ajax/Ajaxupload')}";
            var id = $("input[name='room[rid]']").val();
            $.ajaxFileUpload
            (
                {
                    url: url,
                    secureuri: false,
                    data:{rid:id},
                    fileElementId: 'img',
                    dataType: 'json',
                    success: function (data, status)
                    {
                        $('#img-url').val(data.data.img);
                        $('#img').parent('li').remove();
                        var html = '<li style="height: 220px" id="used-type"><label>户型图：</label><div style="display:inline-table;width: 200px;height: 200px"><img src="'+data.data.img+'" width="200px" height="200px"/> </div> <button onclick="alter (this)">修改</button></li>';
                        $('#mating').after(html)
                        layer.closeAll();
                    },
                    error: function (data, status, e)
                    {
                        layer.msg('上传失败', {icon: 0});
                    }
                }
            )

        }, function(){
            $('#proportion').val("{$unit.area}");
            layer.msg('已取消！', {icon: 0});
        });
    })
    //电话查询
    $('input[name="data[phone]"]').change(function (v){
        var phone = $(this).val ();
        var url = "{:U('Ajax/getPhone')}";
        var data = {phone:phone};
        $.post (url, data, function (response){
            var data = response.data;
            var link = "{:U('used/edit')}";
            if (response.state == 'ok'){
                var html = '<div><ul>';
                $.each (data, function (i,v){
                    html += '<li><a href="'+link+'&id='+v.id+'" style="height: 30px;font-size: 16px;text-align: center" target="_blank">'+v.title+'<em style="' +
                            'color:#A8A8A8;font-size: 10;">('+v.balias+v.ualias+'单元'+v.alias+')</em></a></li>';
                });
                html += '</ul></div>'
                layer.open({
                    type: 1,
                    area: ['300px', ''],
                    anim: 2,
                    content: html
                });
            }
        },'json');

    });


</script>
<include file="Public:footer" />